﻿package mortal.game.view.market
{
    import com.gengine.resource.*;
    import com.mui.events.*;
    import extend.language.*;
    import mortal.component.window.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.market.buyAndQiugou.*;
    import mortal.game.view.market.qiugou.*;
    import mortal.game.view.market.sale.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.interfaces.*;

    public class MarketModule extends BaseWindow
    {
        private var _buyPanel:MarketBuyPanel;
        private var _salePanel:MarketSalePanel;
        private var _qiugouPanel:MarketQiugouPanel;
        private var _tabBar:GTabarNew;
        private var _tabData:Array;
        private var _isResCompl:Boolean = false;

        public function MarketModule(param1:ILayer = null)
        {
            super(param1);
            MktModConfig.createData();
            this.init();
            return;
        }// end function

        public function init() : void
        {
            setSize(688, 520);
            title = "市场";
            this.titleHeight = 60;
            this._tabData = Language.getArray(50501);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.market, this.showSkin);
            return;
        }// end function

        private function showSkin() : void
        {
            this._isResCompl = true;
            this._tabBar = UIFactory.gTabBarNew(4, 30, this._tabData, 686, 522, 65, 26, this, this.tabBarChangeHandler, "TabButtonNew");
            this._tabBar.selectedIndex = 0;
            this.tabBarChangeHandler(null);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._tabBar.dispose(param1);
            this._tabBar = null;
            this.disposeTabPanel([0, 1, 2, 3], param1);
            return;
        }// end function

        public function refresh() : void
        {
            if (!this.stage)
            {
                return;
            }
            switch(this._tabBar.selectedIndex)
            {
                case 0:
                case 1:
                {
                    this._buyPanel.search();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function disposeTabPanel(param1:Array, param2:Boolean = true) : void
        {
            var _loc_3:int = 0;
            while (_loc_3 < param1.length)
            {
                
                if (this._buyPanel && (param1[_loc_3] == 0 || param1[_loc_3] == 1))
                {
                    this._buyPanel.dispose(param2);
                    this._buyPanel = null;
                }
                if (this._salePanel && param1[_loc_3] == 2)
                {
                    this._salePanel.dispose(param2);
                    this._salePanel = null;
                }
                if (this._qiugouPanel && param1[_loc_3] == 3)
                {
                    this._qiugouPanel.dispose(param2);
                    this._qiugouPanel = null;
                }
                _loc_3++;
            }
            return;
        }// end function

        private function tabBarChangeHandler(event:MuiEvent = null) : void
        {
            if (this._buyPanel)
            {
                this._buyPanel.visible = false;
            }
            if (this._salePanel)
            {
                this._salePanel.visible = false;
            }
            if (this._qiugouPanel)
            {
                this._qiugouPanel.visible = false;
            }
            switch(this._tabBar.selectedIndex)
            {
                case 0:
                {
                    if (this._buyPanel == null)
                    {
                        this._buyPanel = UIFactory.getUICompoment(MarketBuyPanel, 0, 0, this);
                    }
                    this._buyPanel.visible = true;
                    this.disposeTabPanel([2, 3]);
                    this._buyPanel.buyOrQiugou = 1;
                    break;
                }
                case 1:
                {
                    if (this._buyPanel == null)
                    {
                        this._buyPanel = UIFactory.getUICompoment(MarketBuyPanel, 0, 0, this);
                    }
                    this._buyPanel.visible = true;
                    this.disposeTabPanel([2, 3]);
                    this._buyPanel.buyOrQiugou = 2;
                    break;
                }
                case 2:
                {
                    if (this._salePanel == null)
                    {
                        this._salePanel = UIFactory.getUICompoment(MarketSalePanel, 0, 0, this);
                    }
                    this.disposeTabPanel([0, 1, 3]);
                    this._salePanel.visible = true;
                    break;
                }
                case 3:
                {
                    if (this._qiugouPanel == null)
                    {
                        this._qiugouPanel = UIFactory.getUICompoment(MarketQiugouPanel, 0, 0, this);
                    }
                    this.disposeTabPanel([0, 1, 2]);
                    this._qiugouPanel.visible = true;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
